package domain;

public class Item {

	private String id;
	private String text;
	private String title;
	private String path;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getText() {
		if (text != null && !text.equals("")) {
			text = parseText(text);
			int index = 0;
			int length = text.length();
			if (length > 1) {
				char c = text.charAt(0);
				if (isChineseEnglish(c).equals("是特殊符号")) {
					index = 1;
				}
				if (length > 4) {
					if (text.substring(0, 4).equals("<em>")) {
						index = 0;
					}
				}
				if (length > 100) {
					text = text.substring(index, 100) + "...";
					return text;
				}
			}
		}

		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String isChineseEnglish(char c) {
		if (c >= 0 && c <= 9) {
			// 是数字
			return "是数字字符";
		} else if ((c >= 'a' && c <= 'z')) {
			// 是小写字母
			return "是小写字母";
		} else if ((c >= 'A' && c <= 'z')) {
			// 是大写字母
			return "是大写字母";
		} else if (Character.isLetter(c)) {
			// 是汉字
			return "是汉字字符";
		} else {
			// 是特殊符号
			return "是特殊符号";
		}
	}

	public String getTitle() {
		title = parseText(title);
		return title;
	}

	public String parseText(String str) {
		// 去掉除<em></em>以外的html
		if (str != null && str != "") {
			str = str.replaceAll("<[^e></][^m><][^><]*>", "")
					.replaceAll("</[^e><][^m><][^><]*>", "")
					.replaceAll("<[a-zA-Z]>", "")// 去除单个<>标签
					.replaceAll("<img.*>", "").replaceAll("　", "").trim();
		}
		return str;

	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

}
